﻿using System.ComponentModel;
using VNet.VisiSuite.Common.Resource;
using VNet.VisiSuite.VisiBoard.Common.Helpers;
using VNet.VisiSuite.Controls;
using System.Windows;
using VNet.VisiSuite.VisiBoard.Models;
using VNet.VisiSuite.VisiBoard.Common;
using System.Collections.ObjectModel;

namespace VNet.VisiSuite.VisiBoard.ViewModels
{
    public abstract class DialogViewModel : INotifyPropertyChanged
    {
        #region Implement INotifiedPropertyChanged

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

#region Fields
        private bool _is_busy;
        private string _error_message;
        private string _heading;
#endregion

        #region Common Properties

        public string Heading
        {
            get { return _heading; }
            set
            {
                _heading = value;
                OnPropertyChanged("Heading");
            }
        }


        public bool IsBusy
        {
            get { return _is_busy; }
            set
            {
                _is_busy = value;
                OnPropertyChanged("IsBusy");
            }
        }


        public string ErrorMessage
        {
            get { return _error_message; }
            set
            {
                _error_message = value;
                OnPropertyChanged("ErrorMessage");
            }
        }


        #endregion

        #region Async method to invoke service

        private BackgroundWorker _worker;

        protected void DoAsync(DoWorkEventHandler doWork, RunWorkerCompletedEventHandler completed, object obj = null)
        {
            _worker = new BackgroundWorker { WorkerReportsProgress = false, WorkerSupportsCancellation = false };
            _worker.DoWork += doWork;
            _worker.RunWorkerCompleted += completed;
            _worker.RunWorkerAsync(obj);
        }

        #endregion

    }
}